//
//  HRBindingPayViewController.m
//  Hear
//
//  Created by mac on 2018/1/3.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HRBindingPayViewController.h"
#import "HRMoneyViewModel.h"
@interface HRBindingPayViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UIButton *enterButton;
@property(nonatomic, strong)HRMoneyViewModel *viewModel;

@end

@implementation HRBindingPayViewController

#pragma mark - Get and Set
- (HRMoneyViewModel *)viewModel{
    if (_viewModel == nil) {
        _viewModel = [[HRMoneyViewModel alloc] init];
    }
    return _viewModel;
}



- (IBAction)enterClick:(id)sender {
    [self.view endEditing:NO];
    if (!self.textField.text.length){
        [MBProgressHUD showMessage:@"支付宝不能为空" finishBlock:nil];
    }
    WeakSelf
    [self.viewModel postSaveUserAlipayInfo:@{@"UserLocalId":USERID,@"AlipayName":self.textField.text,@"CreateTime":[self getCurrentTime]} isSeccess:^(BOOL isSeccess) {
        if (isSeccess){
            [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadIconAndBackGroundNotififation" object:nil];
            [MBProgressHUD showMessage:@"绑定成功" finishBlock:nil];
            [weakSelf.navigationController popViewControllerAnimated:YES];
            if (weakSelf.bindingBlock){
                weakSelf.bindingBlock(weakSelf.textField.text);
            }
        }
    }];
}

- (NSString *)getCurrentTime
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    return [formatter stringFromDate:[NSDate date]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
    // Do any additional setup after loading the view from its nib.
}

- (void)setupView{
    self.enterButton.clipsToBounds = YES;
    self.enterButton.layer.cornerRadius = 8;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
